const txtLoginIdValidator = new FiledValidator('txtLoginId', async function (val) {
    if (!val) {
        return '账号不为空'
    }
})

const txtLoginPwdValidator = new FiledValidator('txtLoginPwd', async function (val) {
    if (!val) {
        return '密码不为空'
    }
})

const form = $('.user-form')
form.onsubmit = async function (e) {
    e.preventDefault();
    const result = FiledValidator.validate(txtLoginIdValidator, txtLoginPwdValidator);
    if (!result) {
        return
    }


    const formData = new FormData(form);
    const data = Object.fromEntries(formData.entries());

    const resp = await API.login(data);
    if (resp.code === 0) {
        alert('登录成功');
        location.href = './index.html'
    } else {
        console.log(resp)
        alert(resp.msg)
    }
}